/**
 * \file
 *           tlmServiceMsg.cpp
 * \brief
 *           Implements tlmServiceMsg class for Telematics
 *           this is the class for service message
 *
 * \par Author (last changes):
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Project Leader:
 *          -
 * \par Responsible Developer:
 *          - Zeng Jie
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Architect:
 *          - Zhang Fa
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 *
 * \par Project:
 *      DPCA2
 *
 * \par SW-Component:
 *      Telematics
 *
 * \par SW-Package:
 *      Telematics
 *
 * \par SW-Module:
 *      Telematics Application
 *
 * \par SW-Architecture Specification:
 *      DPCA –TELEMATICS SW DD
 *      05b
 *
 * \par SW-Design Specification:
 *      DPCA –TELEMATICS SW DD
 *      05b
 *
 * \par SW-Test Case Specification:
 *
 * \par CM-Info:
 *
 * \note
 *      This is a note.
 *
 * \bug
 *      - there are no known bugs
 *
 * \par Module-History:
 *
 * \verbatim
 * Date                Author					Reason
 * 10 Dec 2013        Zeng Jie              Initial Creation
 * The latest entry at the head of the history list.
 * \endverbatim
 *
 * \par Copyright Notice:
 * Copyright (C) 2012 Continental Automotive Holdings Co., Ltd.
 * Alle Rechte vorbehalten. All Rights Reserved.\n
 * The reproduction, transmission or use of this document or its contents is
 * not permitted without express written authority.\n
 * Offenders will be liable for damages. All rights, including rights created
 * by patent grant or registration of a utility model or design, are reserved.
 *
 */
#include "stdafx.h"
#include "string.h"
#include "tlmServiceMsg.h"
#include "teleLogTrace.h"
#include <windows.h>




/**
* \brief tlmServiceMsg: this is default constructor function of tlmServiceMsg
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*
*/
tlmServiceMsg::tlmServiceMsg() : mpDataInfo(NIL) {
}

/**
* \brief tlmServiceMsg: this is constructor function of tlmServiceMsg
*                   it use message string and size to init this object
*                   it's always used on received message
*
* \note
*
* \param[in]
* - msgString: message buffer pointer
*   size: size of the message
*
* \return
* - none
*
*/
tlmServiceMsg::tlmServiceMsg(const uint8_t* msgString, const uint32_t size) : mMsgLen(size), mpDataInfo(NIL){
    //#[ operation tlmServiceMsg(uint8_t*,uint32_t)
    
    mInMsgPtr = new unsigned char[size];
    memcpy(mInMsgPtr, msgString, size);
    
    mInboundMsgBuf.setMsgBufferPtr(mInMsgPtr);
    //here we only set the header length, as we only parse the header
    mInboundMsgBuf.setMsgBufferSize(TLM_NGTP_HEADER_LENGTH);
    
    //#]
}

/**
* \brief tlmServiceMsg: this is constructor function of tlmServiceMsg
*                   it use srvType and msgType to init object
*                   it's always used on send out message
*
* \note
*
* \param[in]
* - srvType: service type
*   msgType: message type
*
* \return
* - none
*
*/
tlmServiceMsg::tlmServiceMsg(uint8_t srvType, uint8_t msgType) : mpDataInfo(NIL){
    //#]
}

/**
* \brief ~tlmServiceMsg: this is destructor of tlmServiceMsg class
*                   it deletes all allocated memory in the constructor function
*
* \note
*
* \param[in]
* - none
*
* \return
* - none
*/
tlmServiceMsg::~tlmServiceMsg() {

    if(mInMsgPtr!=NIL)
    {//delete the allocated buffer
    	delete [] mInMsgPtr; 
    	mInMsgPtr=NIL;
    }    

    if(mpDataInfo!=NIL)
    {
        delete mpDataInfo;
        mpDataInfo=NIL;
    }
}


/**
* \brief ParseMsgHeader: parse the message header and set its attribute
*           This function only parse the header, it read information from
*           the message. If reach end of the message or read an filde code
*           which is not in the header part, it shall stop the parse
*
* \note
*
* \param[in]
* - none
*
* \return
* - bool_t: true - parse message successfully.
*         false - parse message failed
*
* DesignID:MRN_TLM-SRV_SW_DD_127
*/
bool_t tlmServiceMsg::ParseMsgHeader() {
    bool_t retVal = true;
    uint32_t dataLen=0;
    uint32_t totalLen=0;
    uint8_t value = 0;
    //this is the header item code list, it's in sequence.
    //It's used to check the header item is send in sequence.
    uint8_t codeList[TLM_NGTP_HEADER_CODE_COUNT]={TLM_NGTP_HEADER_CODE_PROTOCOL_VERSION,
                                                  TLM_NGTP_HEADER_CODE_VIN,
                                                  TLM_NGTP_HEADER_CODE_ROUTE_INFO ,
                                                  TLM_NGTP_HEADER_CODE_MSG_UNIQUE_ID,
                                                  TLM_NGTP_HEADER_CODE_SERVICE_TYPE,
                                                  TLM_NGTP_HEADER_CODE_MESSAGE_TYPE,
                                                  TLM_NGTP_HEADER_CODE_DATE_TIME,
                                                  TLM_NGTP_HEADER_CODE_MSG_PROTOCOL_VERSION,
                                                  TLM_NGTP_HEADER_CODE_DATA_LENGTH
                                                  };

    
    uint8_t i=0;
    //the first byte should header item code
	while(!mInboundMsgBuf.IsReachEnd())
    {
        //first get the code  
    	GetValue(value); 
        if(value != codeList[i])
        {//the code at this position is not valid.
            retVal = false;
            break;
        }
        else
        {
            retVal = InitHeaderItem(value);
    	    if(!retVal)
            {//the code is not valid, need to discard the message
                break; //here is the end of header
            }
        }

        if(retVal&&(!mInboundMsgBuf.IsReachEnd()))
        {//after the element value, it should be sep "0x7E"    
        	retVal = GetValue(value);
            if(value != SEPERATE_LEVEL_1)
            {//invalid sepeartor, no need to check the message
    	        LOG_PRINT(DPCA_TELE_MSGSRV_ERROR,"[TLM_MSGSRV]: <tlmRmtCfgSrvMsg::ParseInit>invalide Seperator[%d], no need to parse the message\r\n",value);
                 
                retVal = false;
                break;
            }
        }

        i++;
    }  

    if(retVal)
    {
    	//after parse the header, it should be data info buf
    	mDataInfoMsgPtr = mInboundMsgBuf.getCurPtr();

        totalLen = mHdDataLength + TLM_NGTP_HEADER_LENGTH;
        if(totalLen != mMsgLen)
        {//the size calcluated not equal the message size
    	    LOG_PRINT(DPCA_TELE_MSGSRV_ERROR,"[TLM_MSGSRV]: <tlmRmtCfgSrvMsg::ParseInit>, message length not match<Actual - %d:Expected - %d>\r\n", totalLen, mMsgLen);
            retVal = false;
        }
    }

    return retVal;
}


/**
* \brief InitHeaderItem:This function is used to initialize the header item base on the item code
*                       It reads value from message buffer, the size is depend on the item code.
*
* \note
*
* \param[in]
* - uint8_t code
*
* \return
* bool_t - true: init header item successfully.
*       false: init header item failed which means the code is invalid.
*
* DesignID: MRN_TLM-SRV_SW_DD_142
*/
bool_t tlmServiceMsg::InitHeaderItem(const uint8_t& code){
    bool_t retVal = true;
    uint8_t rawDateTime[TLM_NGTP_HEADER_SIZE_DATE_TIME];
    uint8_t rawDataLen[TLM_NGTP_HEADER_SIZE_DATA_LENGTH];

    switch(code)
    {
        case TLM_NGTP_HEADER_CODE_PROTOCOL_VERSION:
            GetValue(mHdProtocolVersion);
            break;
        case TLM_NGTP_HEADER_CODE_VIN :
            GetData(mHdVin,TLM_NGTP_HEADER_SIZE_VIN);
            break;
        case TLM_NGTP_HEADER_CODE_ROUTE_INFO :
            GetData(reinterpret_cast<uint8_t*>(&mHdRouteInfo),TLM_NGTP_HEADER_SIZE_ROUTE_INFO);
            break;
        case TLM_NGTP_HEADER_CODE_MSG_UNIQUE_ID :
            GetData(reinterpret_cast<uint8_t*>(&mHdMsgUniqueId),TLM_NGTP_HEADER_SIZE_MSG_UNIQUE_ID);
            break;
        case TLM_NGTP_HEADER_CODE_SERVICE_TYPE:
            GetValue(mHdSrvType);
            break;
        case TLM_NGTP_HEADER_CODE_MESSAGE_TYPE:
            GetValue(mHdMsgType);
            break;
        case TLM_NGTP_HEADER_CODE_DATE_TIME:
            GetData(rawDateTime,TLM_NGTP_HEADER_SIZE_DATE_TIME);
            SetDateTime(rawDateTime);
            break;
        case TLM_NGTP_HEADER_CODE_MSG_PROTOCOL_VERSION  :
            GetValue(mHdMsgProtocolVersion);
            break;
        case TLM_NGTP_HEADER_CODE_DATA_LENGTH           :
            GetData(rawDataLen,TLM_NGTP_HEADER_SIZE_DATA_LENGTH);
            SetDataLength(rawDataLen);
            break;
        default:
            retVal = false;
            break;
    }
    return retVal;
}
/**
* \brief SetDataLength:This function is used to set data length item.
*                      the raw data lenth filed is 3 bytes, the function conerts these 3 bytes to an uint32_t value
*
* \note
*
* \param[in]
* - uint8_t* rawDataLen
*
* \return
* bool_t -true: set datalength item successfully.
*      false: set datalength item failed
*
* DesignID: MRN_TLM-SRV_SW_DD_143
*/
bool_t tlmServiceMsg::SetDataLength(uint8_t * rawDataLen){
    uint8_t * p=NIL;
    bool_t retVal = true;
    
    p=rawDataLen;
    if(p==NIL)
    {
        LOG_PRINT(DPCA_TELE_MSGSRV_ERROR,"[TLM_MSGSRV]: <tlmRmtCfgSrvMsg::SetDataLength> value ptr for datainfolen is NIL\r\n");
        mHdDataLength=0;
        retVal=false;
    }
    else
    {
        mHdDataLength = (*p)<<16 | (*(p+1))<<8 | (*(p+2));
    }
    return retVal;
}

void tlmServiceMsg::SetDataLength(uint32_t dataLength){

    mHdDataLength = dataLength;
}
/**
* \brief SetDateTime:This function is used to set date and time
*                       the raw date time filed is 4 bytes, the function conerts these 4 bytes into year, month, day, hour, minute, second
*
* \note
*
* \param[in]
* - uint8_t* rawDateTime
*
* \return
* bool_t -true: set date time item successfully.
*      false: set date time item failed
*
* DesignID: MRN_TLM-SRV_SW_DD_144
*/
bool_t tlmServiceMsg::SetDateTime(uint8_t * rawDateTime){
    uint8_t * p = NIL;
    bool_t retVal = true;

    p=rawDateTime;
    if(p==NIL)
    {
        LOG_PRINT(DPCA_TELE_MSGSRV_ERROR,"[TLM_MSGSRV]: <tlmRmtCfgSrvMsg::SetDateTime> value ptr for datetime is NIL\r\n");
        mHdYear=0;
        mHdMonth=0;
        mHdDay=0;
        mHdHour=0;
        mHdMinute=0;
        mHdSecond=0;
    }
    //Date Time format
    //Byte       0           1                  2                 3
    // 7 6 5 4 3 2 1 0  7 6 5 4 3 2 1 0   7 6 5 4 3 2 1 0   7 6 5 4 3 2 1 0
    // Y Y Y Y Y Y M M  M M D D D D D H   H H H H M M M M   M M S S S S S S

    mHdYear= ((*p) >> 2) & 0x3f;
    mHdMonth = (((*p) & 0x03) << 2) | (((*(p+1)) >> 6) & 0x03);
    mHdDay = (*(p+1) >> 1) & 0x1f;
    mHdHour = (((*(p+1)) & 0x01) << 4) | (((*(p+2)) >> 4) & 0x0f);
    mHdMonth = (((*(p+2)) & 0x0f) << 2) | (((*(p+3)) >> 6) & 0x03);
    mHdSecond = (((*(p+3)) >> 6) & 0x03);

    return retVal;
}
/**
* \brief GetDataInfoBuf:get the pointer to data info buffer
*                       This buffer include the seperate 7E that followed by data length filed
*
* \note
*
* \param[in]
* - none
*
* \return
*   uint8_t * the pointer to data info buffer
*
* DesignID: MRN_TLM-SRV_SW_DD_145
*/

uint8_t* tlmServiceMsg::GetDataInfoBuf(void) const{
    return mDataInfoMsgPtr;
}

/**
* \brief GetSrvType:
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t: the serve type value of the message 
*
* DesignID: MRN_TLM-SRV_SW_DD_129
*/
uint8_t tlmServiceMsg::GetSrvType(void) const{
    return mHdSrvType;
}

void tlmServiceMsg::SetSrvType(uint8_t srvType) {
    mHdSrvType = srvType;
}
/**
* \brief GetMsgType:
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t: the message type value of the message 
*
* DesignID: MRN_TLM-SRV_SW_DD_128
*/
uint8_t tlmServiceMsg::GetMsgType(void) const{
    return mHdMsgType;
}

void tlmServiceMsg::SetMsgType(uint8_t msgType) {
    mHdMsgType = msgType;
}
/**
* \brief GetProtocolVer: get the protocol version of the message
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t: the protocol version value of the message 
*
* DesignID: MRN_TLM-SRV_SW_DD_130
*/
uint8_t tlmServiceMsg::GetProtocolVer(void) const{
    return mHdProtocolVersion;
}

/**
* \brief GetVin: get the vin buffer of the message
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t *: the pointer to VIN buffer
*
* DesignID: MRN_TLM-SRV_SW_DD_131
*/
uint8_t * tlmServiceMsg::GetVin(void) {
    return reinterpret_cast<uint8_t*>(mHdVin);
}

void tlmServiceMsg::SetVin(uint8_t *vin) {
    memcpy(mHdVin, vin, TLM_NGTP_HEADER_SIZE_VIN);
}
/**
* \brief GetRouteInfo: Get the route info filed of the message
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint16_t : route info value
*
* DesignID: MRN_TLM-SRV_SW_DD_132
*/
uint16_t  tlmServiceMsg::GetRouteInfo(void) const{
    return mHdRouteInfo;
}


/**
* \brief GetRouteInfo: Get the messge unique id filed of the message
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint16_t : message unique id vlaue 
*
* DesignID: MRN_TLM-SRV_SW_DD_133
*/
uint16_t  tlmServiceMsg::GetMsgUniqueId(void) const{
    return mHdMsgUniqueId;
}

void tlmServiceMsg::SetMsgUniqueId(uint16_t msgUniqueId) {
    mHdMsgUniqueId = msgUniqueId;
}
/**
* \brief GetYear: Get the year
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : year of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_134
*/
uint32_t  tlmServiceMsg::GetYear(void) const{
    return mHdYear;
}
/**
* \brief GetMonth: Get the month
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : month of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_135
*/
uint32_t  tlmServiceMsg::GetMonth(void) const{
    return mHdMonth;
}
/**
* \brief GetDay: Get the Day
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : Day of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_136
*/
uint32_t  tlmServiceMsg::GetDay(void) const{
    return mHdDay;
}
/**
* \brief GetHour: Get the Hour
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : Hour of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_137
*/
uint32_t  tlmServiceMsg::GetHour(void) const{
    return mHdHour;
}
/**
* \brief GetMinute: Get the Minute
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : Minute of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_138
*/
uint32_t  tlmServiceMsg::GetMinute(void) const{
    return mHdMinute;
}
/**
* \brief GetSecond: Get the second
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t : second of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_139
*/
uint32_t  tlmServiceMsg::GetSecond(void) const{
    return mHdSecond;
}
/**
* \brief GetMsgProtocolVer: Get the message protocol version
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint8_t : message protocol version of the message
*
* DesignID: MRN_TLM-SRV_SW_DD_140
*/
uint8_t  tlmServiceMsg::GetMsgProtocolVer(void) const{
    return mHdMsgProtocolVersion;
}
/**
* \brief GetDataInfoLength: get data info length which is in the length section of the message
*
* \note
*
* \param[in]
* - none
*
* \return
* - uint32_t: the length of data info
*
* DesignID: MRN_TLM-SRV_SW_DD_141
*/
uint32_t tlmServiceMsg::GetDataInfoLength(void) const{
    return mHdDataLength;
}

/**
* \brief GetValue: get one byte data value from the message buffer 
*
* \note
*
* \param[in]
* - value: variable to save the read data value
*
* \return
* - bool_t: true - get value successfully.
*         false - get value failed
*
* DesignID: MRN_TLM-SRV_SW_DD_069
*/
bool_t tlmServiceMsg::GetValue(uint8_t& value) {
    //#[ operation GetValue(uint8_t&)
    return mInboundMsgBuf.getValue(value);
    //#]
}

/**
* \brief GetData: get data content from the message buffer 
*
* \note
*
* \param[in]
* - buf:buffer to save the read data 
*   size: size of the data that want to be read
*
* \return
* - bool_t: true - get data successfully.
*         false - get data failed
*
* DesignID: MRN_TLM-SRV_SW_DD_065
*/
bool_t tlmServiceMsg::GetData(uint8_t* buf, uint32_t size) {
    //#[ operation GetData(uint8_t*,uint32_t)
    //#]
	return mInboundMsgBuf.getData(buf, size);

}


bool_t tlmServiceMsg::SetValue(uint8_t value) {
    //#[ operation SetValue(uint8_t)
    return mOutboundMsgBuf.setValue(value);
    //#]
}

bool_t tlmServiceMsg::SetData(uint8_t * buf, uint32_t size) {
    //#[ operation SetData(uint8_t *,uint32_t)
    return mOutboundMsgBuf.setData(buf, size);
    //#]
}

uint8_t* tlmServiceMsg::GetMsgBuf(void) const{
    return mInMsgPtr;
}

uint32_t tlmServiceMsg::GetMsgLen(void) const{
    return mMsgLen;
}



void tlmServiceMsg::SetProtocolVer(uint8_t protocolVer){
    mHdProtocolVersion = protocolVer;
}

void tlmServiceMsg::SetRouteInfo(uint16_t routeInfo){
    mHdRouteInfo = routeInfo;
}

void tlmServiceMsg::SetYear(uint32_t year){
    mHdYear = year;
}

void tlmServiceMsg::SetMonth(uint32_t month){
    mHdMonth = month;
}
void tlmServiceMsg::SetDay(uint32_t day){
    mHdDay = day;
}
void tlmServiceMsg::SetHour(uint32_t hour){
    mHdHour = hour;
}
void tlmServiceMsg::SetMinute(uint32_t minute){
    mHdMinute = minute;
}
void tlmServiceMsg::SetSecond(uint32_t second){
    mHdSecond = second;
}

void  tlmServiceMsg::SetMsgProtcolVer(uint8_t msgProtcolVer){
    mHdProtocolVersion = msgProtcolVer;
}
/**
* \brief Init: This function initialize the element of message
*              It uses default value to do initialization, the
*              user shall call related function to change the value.
*
* \note
*
* \param[in]
* - none
*
* \return
* - bool_t: true - Init successfully.
*         false - Init failed
*
* 
*/
bool_t tlmServiceMsg::Init(void){
    bool_t retVal = true;
    uint8_t proVersion=1;
    uint8_t vin[TLM_RMT_CFG_HEADER_VIN_VALUE_SIZE+1]={0};
    uint16_t routeInfo=0;
    uint16_t uniqueId=0;
    uint8_t msgProVersion=1;
    uint32_t dataInfoLen=0; 
    
    //TODO:need get current settings.
    //
    SetProtocolVer(proVersion);
    SetVin("TESTVIN123");

    SetRouteInfo(routeInfo);
    SetMsgUniqueId(uniqueId);
	//TODO:implement DateTime
    SetYear(0);
    SetMonth(0);
    SetDay(0);
    SetHour(0);
    SetMinute(0);
    SetSecond(0);
    SetMsgProtcolVer(msgProVersion);   
    
    //do not set dataInfoLen, as we don't the actual data info length until we fill the buffer.
    
    if(mpDataInfo != NIL)
    {
        //the datainfo shall initialize its own element.
        mpDataInfo->Init();
    }
    
    
    return retVal;
}

bool_t tlmServiceMsg::Fill(){
    //#[ operation Fill()
    bool_t retVal=true; 
    uint32_t dataInfoSize=0;
    
    //As we don't know actual size of data info until fill it
    //we first fill the data info ,get the actual length, then fill the header
    if(mpDataInfo != NIL)
    {//This message has data info, we should fill it, the buffer has been set when create this msg object.  
    	mpDataInfo->Fill(); 
    	
    	//after fill, we know the actual datainfo size.
    	dataInfoSize=mpDataInfo->GetDataInfoSize();
    } 
    
    SetDataLength(dataInfoSize);
    
    retVal = FillHeader(); 
    
    return retVal;
    //#]
}

void tlmServiceMsg::FillHeader() {


    //Fill protocol version
    SetValue(TLM_NGTP_HEADER_CODE_PROTOCOL_VERSION);
    SetValue(mHdProtocolVersion);

    SetValue(SEPERATE_LEVEL_1);

    //Fill 10 bytes vin
    SetValue(TLM_NGTP_HEADER_CODE_VIN);
    SetData(mHdVin, TLM_NGTP_HEADER_SIZE_VIN);

    SetValue(SEPERATE_LEVEL_1);

    //Fill route info
    uint16_t routeInfo = htons(mHdRouteInfo);
    SetValue(TLM_NGTP_HEADER_CODE_ROUTE_INFO);
    SetData(&routeInfo, TLM_NGTP_HEADER_SIZE_ROUTE_INFO);

    SetValue(SEPERATE_LEVEL_1);

    //Fill message unique ID
    uint16_t uniId = htons(mHdMsgUniqueId);
    SetValue(TLM_NGTP_HEADER_CODE_MSG_UNIQUE_ID);
    SetData(&uniId, TLM_NGTP_HEADER_SIZE_MSG_UNIQUE_ID);

    SetValue(SEPERATE_LEVEL_1);

    //Fill serve type
    SetValue(TLM_NGTP_HEADER_CODE_SERVICE_TYPE);
    SetValue(mHdSrvType);

    SetValue(SEPERATE_LEVEL_1);

    //Fill message type
    SetValue(TLM_NGTP_HEADER_CODE_MESSAGE_TYPE);
    SetValue(mHdMsgType);

    SetValue(SEPERATE_LEVEL_1);
    
    //Fill datetime
    uint32_t dateTime=0;
    TranslateDateTime(&dateTime);
    
    SetValue(TLM_NGTP_HEADER_CODE_DATE_TIME);
    SetDate(&dateTime, TLM_NGTP_HEADER_SIZE_DATE_TIME);

    SetValue(SEPERATE_LEVEL_1);

    //Fill message protocol version
    SetValue(TLM_NGTP_HEADER_CODE_MSG_PROTOCOL_VERSION);
    SetValue(mHdMsgProtocolVersion);

    SetValue(SEPERATE_LEVEL_1);

    //Fill data length
    uint8_t tmpVal[3]={0};   
    tmpVal[0]= (mHdDataLength & 0xff0000) >> 16;
    tmpVal[1]= (mHdDataLength & 0xff00) >> 8; 
    tmpVal[2]= (mHdDataLength & 0xff);

    SetValue(TLM_NGTP_HEADER_CODE_DATA_LENGTH);
    SetData(tmpVal, TLM_NGTP_HEADER_SIZE_DATA_LENGTH);

}


void tlmServiceMsg::TranslateDateTime(uint8_t * dateTime)
{
	dateTime[0] = ((mHdYear & 0x3f) << 2) | ((mHdMonth & 0x0f)>>2);
	dateTime[1] = ((mHdMonth & 0x0f) << 6) | ((mHdDay & 0x1f)<<1) | ((mHdHour & 0x1f)>>4);
	dateTime[2] = ((mHdHour & 0x1f)<<4) | ((mHdMinute & 0x3f)>>2);
	dateTime[3] = ((mHdMinute & 0x3f)<<6)| (mHdSecond & 0x3f);
}
